<?php
 
 namespace Core;

abstract class Facade
{
    protected static $container;
    
    // 设置容器实例
    public static function setContainer(Container $container)
    {
        static::$container = $container;
    }
    
    // 获取容器实例
    public static function getContainer()
    {
        return static::$container;
    }
    
    // 获取门面对应的服务名称
    protected static function getFacadeAccessor()
    {
        throw new \Exception('Facade does not implement getFacadeAccessor method.');
    }
    
    // 处理静态调用
    public static function __callStatic($method, $args)
    {
        $instance = static::getContainer()->make(static::getFacadeAccessor());
        
        if (!method_exists($instance, $method)) {
            throw new \Exception("Method {$method} does not exist on " . get_class($instance));
        }
        
        return call_user_func_array([$instance, $method], $args);
    }
}
